<?php
/**
 *
 *
 */
abstract class Yz_Module_WebModule
    extends Yz_Module_Abstract
    implements Yz_Module_WebModule_Interface
{

    protected $webPath;

    const DEFAULT_CONTROLLER = "Default";
    const ERROR_CONTROLLER = false;

    /**
     *  @return string
     */
    public function getWebPath()
    {
        return $this->webPath;
    }

    /**
     *  @return this
     */
    public function setWebPath($path)
    {
        assert('is_string($path)');
        $this->webPath = $path;
        return $this;
    }

    /** select a template by name
     *  @return Yz_Template_Interface&
     *  @throws ClassError
     */
    public function selectTemplate($templateName)
    {
        assert('is_string($templateName) and "" !== $templateName');
        debug($templateName);

        // regardless of what $templateName is supplied, it must match a class
        $class = $this->resolve( 'Template_' . ucfirst($templateName), null );
        assert('is_subclass_of($class,"Yz_Template_Interface")');
        return new $class($this);
    }


    /** find a controller by exact name
     *  @return Yz_Controller_Interface&
     *  @throws ClassError
     */
    public function selectRouter()
    {
        debug();
        $class = $this->resolve( 'Router_Default', 'Yz_Module_Router' );
        assert('is_subclass_of($class,"Yz_Module_Router_Interface")');
        return new $class($this);
    }


    /** find a controller by exact name
     *  @return Yz_Controller_Interface&
     *  @throws ClassError
     */
    public function selectController($ctlrName)
    {
        debug($ctlrName);
        assert('is_string($ctlrName)');
        $class = $this->resolve( 'Controller_' . ucfirst($ctlrName), null );
        assert('is_subclass_of($class,"Yz_Controller_Interface")');
        return new $class($this);
    }


} // class
